<template>
    <div class="login_page" id="sigin">
        <section class="form_contianer">
            <h2 class="login_title">elm后台管理系统</h2>
            <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" class="demo-ruleForm">
                <el-form-item prop="user">
                    <el-input placeholder="用户名" v-model="ruleForm.user"></el-input>
                </el-form-item>
                <el-form-item prop="pass">
                    <el-input placeholder="密码" type="password" v-model="ruleForm.pass" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitForm('ruleForm')">登录</el-button>
                </el-form-item>
            </el-form>
            <div class="tip">
                <h4>温馨提示:</h4>
                <p>未注册的用户将自动注册，注册的用户将直接登录</p>
            </div>
        </section>
    </div>
</template>

<script>
  export default {
    data() {
        var checkAge = (rule, value, callback) => {
            if(!value){
                return callback(new Error('用户名不能为空'))
            }else{
                return callback()
            }
            
        };
        var validatePass = (rule, value, callback) => {
            if (value === '') {
                callback(new Error('请输入密码'));
            } else {
                if (this.ruleForm.checkPass !== '') {
                    this.$refs.ruleForm.validateField('checkPass');
                }
                return callback();
            }
        };
      return {
          ruleForm: {
            pass: '',
            user: ''
            },
            rules: {
                pass: [
                    { validator: validatePass, trigger: 'blur' }
                ],
                user: [
                    { validator: checkAge, trigger: 'blur' }
                ]
            }
        }
    },
    methods: {
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.$router.push({
                        path: '/Main/userList'
                    })
                } else {
                    return false;
                }
            })
        }
    }
}
</script>

<style>
.login_page {
    min-width: 314px;
    min-height: 390px;
    height: 100vh;
    background-color: #324057;
    display: flex;
    justify-content: center;
    align-items: center;
}

.form_contianer {
    background-color: #fff;
    padding: 25px;
    position: relative; 
    border-radius: 5px;
    margin: 100px 10px 10px 10px;
}
.login_title {
    font-weight: normal;
    font-size: 34px;
    color: #fff;
    text-align: center;
    width: 100%;
    position: absolute;
    top: -100px;
    left: 0;
}
.el-form-item__content .el-button--primary {
    width: 100%;
}
.tip {
    font-size: 12px;
    color: red;
}
</style>